package kr.saeildamil.androidforstudy2.ch28;

import java.util.ArrayList;

import kr.saeildamil.androidforstudy2.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter {
	ArrayList<Item> itemList;
	Context context;
	
	public MyAdapter(ArrayList<Item> itemList, Context context){
		this.itemList = itemList;
		this.context = context;
	}
	
	@Override
	public int getCount() {
		return itemList.size();
	}

	@Override
	public Object getItem(int position) {
		return itemList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LinearLayout layout = null;
		TextView itemName = null;
		TextView makerName = null;
		TextView itemPrice = null;
		
		if(convertView == null){
			LayoutInflater inflater =  (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.ch28_itemrow, parent, false);
			/*layout = new LinearLayout(context);
			
			layout.setOrientation(LinearLayout.HORIZONTAL);
			
			itemName = new TextView(context);
			makerName = new TextView(context);
			itemPrice = new TextView(context);
			
			itemName.setId(1);
			makerName.setId(2);
			itemPrice.setId(3);
			
			LayoutParams params = new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
			
			layout.addView(itemName, params);
			layout.addView(makerName, params);
			layout.addView(itemPrice, params);*/
		}
		
		/*itemName = (TextView) convertView.findViewById(1);
		itemName.setText(itemList.get(position).getItemName());
		
		makerName = (TextView) convertView.findViewById(2);
		makerName.setText(itemList.get(position).getMakerName());
		
		itemPrice = (TextView) convertView.findViewById(3);
		itemPrice.setText(itemList.get(position).getItemPrice());*/
		itemName = (TextView) convertView.findViewById(R.id.ch25_textpreferences_frag_text);
		itemName.setText(itemList.get(position).getItemName());
		
		makerName = (TextView) convertView.findViewById(R.id.ch28_itemrow_itemmaker);
		makerName.setText(itemList.get(position).getMakerName());
		
		itemPrice = (TextView) convertView.findViewById(R.id.ch28_itemrow_itemprice);
		itemPrice.setText(Integer.toString(itemList.get(position).getItemPrice()));
		
		return convertView;
	}

}
